﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace WpfCommander
{
    /// <summary>
    /// Interaction logic for ViewItem.xaml
    /// </summary>
    public partial class ViewItem : UserControl
    {
        private bool isSelected;


        public ViewItem()
        {
            this.Index = -1;
            InitializeComponent();
        }


        public int Index { get; set; }

        public string Text { get { return textBlock.Text; } set { textBlock.Text = value; } }

        [DefaultValue(false)]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual bool IsSelected
        {
            get { return isSelected; }
            set
            {
                if (value != isSelected)
                {
                    isSelected = value;

                    if (isSelected)
                    {
                        border.BorderThickness = new Thickness(2);
                        border.BorderBrush = Brushes.SkyBlue;
                    }
                    else
                    {
                        border.BorderThickness = new Thickness(0);
                        border.BorderBrush = Brushes.Black;
                    }

                    if (isSelected)
                    {
                        OnSelected(EventArgs.Empty);
                    }
                }
            }
        }



        public event EventHandler Selected;


        protected virtual void OnSelected(EventArgs e)
        {
            if (Selected != null)
            {
                Selected(this, e);
            }
        }

        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.IsSelected = true;
        }

    }
}
